package com.van.servlet;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.van.service.GreetingService;

public class HelloBeanServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req,HttpServletResponse res){
		
		WebApplicationContext web = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
		GreetingService service = web.getBean(GreetingService.class);
		OutputStream ot;
		try {
			ot = res.getOutputStream();
			ot.write(service.greeting().getBytes());
			ot.flush();
			ot.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
}
